package cate.game.role.bag.item.msg;

import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MergeMsgOutput;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.id.MsgIdBBag;
import cate.game.role.bag.item.Change;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.List;

@ClientMsg(title = "背包物品 数量变更 の 通知")
public class ItemNumResp extends MergeMsgOutput<ItemNumResp> {
    @NoteField(value = "物品对象类型")
    public byte type;

    @NoteField(value = "变更的物品们")
    public List<Change> changes = new ArrayList<>();

    public ItemNumResp() {}

    public ItemNumResp(byte type) {
        this.type = type;
    }

    public ItemNumResp addChange(String uid, long num) {
        changes.add(new Change(uid,num));
        return this;
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBBag.ITEM_NUM_RESP;
    }

    @Override
    public boolean merge(ItemNumResp another) {
        if (another == null || another.type != this.type) {
            return false;
        }
        this.changes.addAll(another.changes);
        return true;
    }
}
